import request from '../../utils/request'
Page({
  data: {
    bannerList:[],
    recommendList:[],
    newAlbum:[],
    topList:[],//排行榜
  },
 toSearch(){
  wx.navigateTo({
    url: '/pages/Search/Search'
  })
},
  async onLoad(options) {
    const date = new Date();
    let day = date.getDate();
    // 如果日期是个位数，则在前面加0
    day = day < 10 ? '0' + day : day;
    // 将当前日期设置到页面的数据中
    this.setData({
        currentDate: day
    });
    let bannerListData = await request('/banner',{type:3});
    this.setData({
      bannerList:bannerListData.banners
    })
    let recommendListData = await request('/personalized',{limit:10});
    this.setData({
      recommendList:recommendListData.result
    })
    let newAlbumData = await request('/album/list',{limit:10});
    this.setData({
      newAlbum:newAlbumData.products
    })
    const allTopListData = await request('/toplist');
    const topList = allTopListData.list.slice(0, 5);
    const topListDetail = [];
    for (let item of topList) {
      const detailList = await request(`/playlist/detail?id=${item.id}`, { limit: 10 });
      topListDetail.push({
        id: item.id, // 确保 id 字段存在
        name: detailList.playlist.name,
        Img: detailList.playlist.coverImgUrl,
        tracks: detailList.playlist.tracks.slice(0, 10)
      });
    }
      this.setData({
      topList: topListDetail
      });
    }
  
});
